/*
 * log.h
 *
 *  Created on: 2008-9-26
 *      Author: fanliangliang
 */

#ifndef TEST_LOG_H_
#define TEST_LOG_H_

#include "toxic.h"
#include <iostream>
#include <fstream>

using namespace std;
using namespace toxic;

static void print_log(int id) {
	xerror("id = %d,%d + %d = %d", id, 1, 2, 3);
	xerror << "id = " << id << "," << 1 << " + " << 2 << " = " << 3;

	xwarn("id = %d,%d + %d = %d", id, 1, 2, 3);
	xwarn << "id = " << id << "," << 1 << " + " << 2 << " = " << 3;

	xinfo("id = %d,%d + %d = %d", id, 1, 2, 3);
	xinfo << "id = " << id << "," << 1 << " + " << 2 << " = " << 3;

	xdebug("id = %d,%d + %d = %d", id, 1, 2, 3);
	xdebug << "id = " << id << "," << 1 << " + " << 2 << " = " << 3;
}

void do_test_log() {

	cout << "***** log *****" << endl;

	xlog.setLevel(LEVEL_WARN);
	xlog.addAppender(cout);
	xlog.addAppender("E:/do_test_log.log");

	vector<Thread*> threads;

	for (int i = 0; i < 10; ++i) {
		Thread* pth = new Thread(toxic::bind(&print_log, i + 1));
		pth->start();
		threads.push_back(pth);
	}

	foreach (Thread* pth, threads) {
		pth->join();
		delete pth;
	}
}

#endif /* TEST_LOG_H_ */
